<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<title>收款统计</title>
		<meta name="renderer" content="webkit">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
		<link rel="stylesheet" href="../../../layuiadmin/layui/css/layui.css" media="all">
		<link rel="stylesheet" href="../../../layuiadmin/style/admin.css" media="all">
		<link rel="stylesheet" href="../../../css/common.css" media="all">
	</head>

	<body>
		<div class="layui-fluid">
			<div class="layui-row layui-col-space15">
				<div class="layui-col-md12">
					<div class="layui-card">
						<div class="layui-tab layui-tab-brief" lay-filter="changetab">
							<ul class="layui-tab-title" id="view_ul">
								<li class="layui-this" lay-id='1'><a href="list.html">按日统计</a></li>
								<li class="" lay-id='0'><a href="list1.html">按月统计</a></li>
							</ul>  
							<div class="layui-card-body">
							<!-- 搜索 -->
							<form class="layui-form search" id="form" onsubmit="return false" action="##">
								<div class="layui-inline search_inline">
									<label class="layui-form-label">支付方式：</label>
									<div class="layui-input-inline">
										<select name="payment">
											<option class="layui-this" value="">全部</option>
											<option value="1">微信</option>
											<option value="2">支付宝</option>
											<option value="3">余额支付</option>
										</select>
									</div>
								</div>
								<div class="layui-inline search_inline">
									<label class="layui-form-label">授权应用编号：</label>
									<div class="layui-input-inline">
										<input class="layui-input" lay-verify="" placeholder="授权应用编号" name="auth_app_id" autocomplete="off">
									</div>
								</div>
								<div class="layui-inline search_inline">
									<label class="layui-form-label">会员编号：</label>
									<div class="layui-input-inline">
										<input class="layui-input" lay-verify="" placeholder="会员编号" name="member_id" autocomplete="off">
									</div>
								</div>
								<div class="layui-inline search_inline">
									<label class="layui-form-label">时间段：</label>
									<div class="layui-input-inline">
										<input class="layui-input" id="choosetime" placeholder="时间段" autocomplete="off">
										<input class="layui-input" type="hidden" name="s_dates" placeholder="" autocomplete="off">
										<input class="layui-input" type="hidden" name="e_dates" placeholder="" autocomplete="off">
									</div>
								</div>
								<button class="layui-btn search_inline" lay-submit="" lay-filter="search" data-type="reload">搜索</button>
								<button class="layui-btn layui-btn-primary search_inline" type="reset">重置</button>
							</form>
							<!-- 搜索 -->

							<table class="layui-hide" id="test-table-operate" lay-filter="test-table-operate"></table>
							<script type="text/html" id="zizeng">
								{{d.LAY_TABLE_INDEX+1}}
							</script>
							<script type="text/html" id="test-table-operate-barDemo">
								<a class="layui-btn layui-btn-xs" lay-event="edit">修改</a>
							</script>
							</div>
						</div>
					</div>
				</div>
			</div>
		</div>
		<script type="text/html" id="zizeng">
				{{d.LAY_TABLE_INDEX+1}}
			</script>
		<script src="../../../layuiadmin/layui/layui.js"></script>
		<script src="../../../js/jquery.min.js" type="text/javascript" charset="utf-8"></script>
		<script src="../../../js/common.js"></script>
		<script>
			layui.config({
				base: '../../../layuiadmin/' //静态资源所在路径
			}).extend({
				index: 'lib/index' //主入口模块
			}).use(['index', 'table', 'form', 'laydate','element','laytpl'], function() {
				var table = layui.table,
					$ = layui.$,
					form = layui.form,
					laydate = layui.laydate,
					element = layui.element,
					laytpl = layui.laytpl,
					admin = layui.admin;
				var _data = {
					s_dates:start(new Date()),
					e_dates:now(new Date()),
					sub_type: '1',
				}
				
				var pro;
				var date = new Date();
				$('input[name=s_dates]').val(_data.s_dates);
				$('input[name=e_dates]').val(_data.e_dates);
				if(_data.sub_type != '1'){
					initdata();
				}else{
					initdata1();
				}

//				card_type();
				
				element.on('tab(changetab)', function(elem) {
					sub_type = this.getAttribute('lay-id');
					_data.sub_type = sub_type;
					pro = sub_type;
					if(pro != '1'){
						initdata();
					}else{
						initdata1();
					}
				});
				
				function initdata1() {
					table.render({
						elem: '#test-table-operate',
						url: server.sys_collection_statistics_by_month_query,
						height: 'full-105',
						toolbar: true,
						totalRow: true,
						cols: [
							[{
								width: 50,
								field: 'zizeng',
								title: '#',
								fixed: 'left',
								templet: '#zizeng'
							},{
								field: 'days',
								width: 180,
								title: '时间'
							},
							// {
							// 	field: 'name',
							// 	width: 180,
							// 	title: '名称'
							// },
							{
								field: 'auth_app_id',
								width: 180,
								title: '授权应用编号'
							},{
								field: 'payment', 
								width: 120,
								title: '支付方式',
								templet: function(d) {
									if(d.payment == 0) {
										return '<span class="text_red_color">' + payment_show(1,d.payment) + '</span>'
									} else if(d.payment == 1){
										return '<span class="text_greed_color">' + payment_show(1,d.payment) + '</span>'
									} else if(d.payment == 2){
										return '<span class="text_blue_color">' + payment_show(1,d.payment) + '</span>'
									} else if(d.payment == 3){
										return '<span class="text_gold_color">' + payment_show(1,d.payment) + '</span>'
									} else {
										return '<span class="text_yellow_color">' + payment_show(1,d.payment) + '</span>'
									}
								},
								totalRowText:'合计：'
							},{
								field: 'fee',
								width: 100,
								title: '交易金额',
								totalRow: true
							}
							]
						],
						page: true,
						where: _data,
						limit: limit,
						limits: limits,
						request: {
							pageName: 'page',
							limitName: 'size',
						},
						parseData: function(res) { //将原始数据解析成 table 组件所规定的数据
							return {
								"code": res.code, //解析接口状态
								"msg": res.msg, //解析提示文本
								"count": res.collections.pager.total, //解析数据长度
								"data": res.collections.data //解析数据列表
							};
						}
					});
				}
				
				function initdata() {
					table.render({
						elem: '#test-table-operate',
						url: server.sys_collection_statistics_by_month_query,
						height: 'full-105',
						toolbar: true,
						totalRow: true,
						cols: [
							[{
								field: 'auth_app_id',
								width: 180,
								title: '授权应用编号'
							},{
								field: 'payment', 
								width: 120,
								title: '支付方式',
								templet: function(d) {
									if(d.payment == 0) {
										return '<span class="text_red_color">' + payment_show(1,d.payment) + '</span>'
									} else if(d.payment == 1){
										return '<span class="text_greed_color">' + payment_show(1,d.payment) + '</span>'
									} else if(d.payment == 2){
										return '<span class="text_blue_color">' + payment_show(1,d.payment) + '</span>'
									} else if(d.payment == 3){
										return '<span class="text_gold_color">' + payment_show(1,d.payment) + '</span>'
									} else {
										return '<span class="text_yellow_color">' + payment_show(1,d.payment) + '</span>'
									}
								}
							},{
								field: 'fee',
								width: 100,
								title: '交易金额'
							},{
								field: 'pay_time',
								width: 180,
								title: '支付时间'
							}
							]
						],
						page: true,
						where: _data,
						limit: limit,
						limits: limits,
						request: {
							pageName: 'page',
							limitName: 'size',
						},
						parseData: function(res) { //将原始数据解析成 table 组件所规定的数据
							return {
								"code": res.code, //解析接口状态
								"msg": res.msg, //解析提示文本
								"count": res.collections_record.pager.total, //解析数据长度
								"data": res.collections_record.data //解析数据列表
							};
						}
					});
				}
//				function card_type() {
//					$.ajax({
//						type: "get",
//						url: server.member_type_list,
//						data:'',
//						async: false,
//						success: function(res) {
//							if(res.code == 0) {
//								var data = res.member_type.data;
//								var getTpl = demo_ul.innerHTML,
//									view = document.getElementById('view_ul');
//								laytpl(getTpl).render(data, function(html) {
//									view.innerHTML = html;
//								});
//								 
//							} else {
//								layer.msg(res.msg);
//							}
//							closeloading();
//						},
//						fail: function(res) {
//							layer.msg('服务器连接错误');
//							closeloading();
//						}
//					});
//					
//				}
				laydate.render({
					elem: '#choosetime',
					type: 'date',
					range: true,
					value: time(date),
					done: function(value, date) {
						$('input[name=s_dates]').val(value.split(' - ')[0]);
						$('input[name=e_dates]').val(value.split(' - ')[1]);
					}
				});
//				laydate.render({
//					elem: '#choosetime1',
//					type: 'month',
//					range: true,
//					value: time1(date),
//					done: function(value, date) {
//						console.log(value);
//						$('input[name=s_dates1]').val(value.split(' - ')[0]);
//						$('input[name=e_dates1]').val(value.split(' - ')[1]);
//					}
//				});

				function start(date){
					var syear = date.getFullYear();
					var smonth = date.getMonth()+1;
					var sday = date.getDate()-1;
					
					if(smonth<10){
						var n = '0'+smonth
						if(sday < 10){
							var d = '0' + sday
							return syear + '-' + n + '-' + d
						}else{
							return syear + '-' + n + '-' +sday
						}						
					}else{
						if(sday < 10){
							var d = '0' + sday
							return syear + '-' + smonth + '-' + d
						}else{
							return syear + '-' + smonth + '-' +sday
						}
						return syear + '-' + smonth + '-' +sday
					}
					
				}

				function now(date){
					var nyear = date.getFullYear();
					var nmonth = date.getMonth()+1;
					var nday = date.getDate();
					if(nmonth<10){
						var n = '0'+nmonth
						if(nday < 10){
							var d = '0' + nday
							return nyear + '-' + n + '-' + d
						}else{
							return nyear + '-' + n + '-' +nday
						}						
					}else{
						if(nday < 10){
							var d = '0' + nday
							return nyear + '-' + nmonth + '-' + d
						}else{
							return nyear + '-' + nmonth + '-' +nday
						}
						return nyear + '-' + nmonth + '-' +nday
					}
				}
				function time(date){
					var time = start(date) + ' - ' + now(date)
					return time
				}
				//监听搜索
				form.verify({
					memberid: function(value, item) { //value：表单的值、item：表单的DOM对象
						if(!value) {
							return '姓名不能为空';
						}
					}
				});

				//监听搜索
				form.on('submit(search)', function(data) {
					if(pro!='1'){
						_data = data.field;
						_data.sub_type = pro;
						initdata1();
						return false;
					}else if(pro=='1'){
						_data = data.field;
						initdata1();
						return false;
					}
				});

				$("button[type=reset]").on("click", function() {
					_data = {
						s_dates:start(new Date()),
						e_dates:now(new Date()),
						sub_type: '1',
					}
					if(_data.sub_type != '1'){
						initdata();
					}else{
						initdata1();
					}
					document.getElementById("form").reset();
				});

				//监听表格复选框选择
				table.on('checkbox(test-table-operate)', function(obj) {
					console.log(obj)
				});

				//监听工具条
				table.on('tool(test-table-operate)', function(obj) {
					var data = obj.data;
					if(obj.event === 'detail') {
						layer.open({
							type: 2,
							title: '客户信息详情',
							shadeClose: false,
							shade: 0.5,
							area: ['600px', '75%'],
							content: 'model/customer_detail.html?id=' + data.memberid,
							end: function() {
								// initdata();
							}
						});
					} else if(obj.event === 'del') {
						layer.confirm('真的删除行么', function(index) {
							obj.del();
							layer.close(index);
						});
					} else if(obj.event === 'edit') {
						layer.open({
							type: 2,
							title: '修改',
							shadeClose: true,
							shade: false,
							maxmin: true, //开启最大化最小化按钮
							area: ['893px', '600px'],
							content: 'model/customer_edit.html?id=' + data.id,
							end: function() {

							}
						});
					} else if(obj.event === 'upreport') {
						layer.open({
							type: 2,
							title: '上传报告',
							shadeClose: false,
							shade: 0.5,
							area: ['500px', '300px'],
							content: 'model/up_report.html?id=' + data.id,
							end: function() {}
						});
					}
				});

				var $ = layui.$,
					active = {
						getCheckData: function() { //获取选中数据
							var checkStatus = table.checkStatus('test-table-operate'),
								data = checkStatus.data;
							layer.alert(JSON.stringify(data));
						},
						getCheckLength: function() { //获取选中数目
							var checkStatus = table.checkStatus('test-table-operate'),
								data = checkStatus.data;
							layer.msg('选中了：' + data.length + ' 个');
						},
						isAll: function() { //验证是否全选
							var checkStatus = table.checkStatus('test-table-operate');
							layer.msg(checkStatus.isAll ? '全选' : '未全选')
						}
					};

				$('.test-table-operate-btn .layui-btn').on('click', function() {
					var type = $(this).data('type');
					active[type] ? active[type].call(this) : '';
				});

			});
		</script>
	</body>

</html>